﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Composite.C1Console.Security;
using LCA.Security;
using LCA.Utils;
using LCA.Common;

public partial class C1Function : Composite.AspNet.UserControlFunction
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GoToHomeIfLoggedIn();
    }

    private void GoToHomeIfLoggedIn()
    {
        if (LCAAuthentication.IsLoggedIn())
        {
            PageHelper.ClientPageRedirect(LCAAuthentication.HomePageId);
        }
    }

    protected void vldCusAuthentication_ServerValidate(object sender, ServerValidateEventArgs args)
    {
        args.IsValid = LCAAuthentication.Authenticate(ctlLogin.UserName, ctlLogin.Password);
    }

    protected void ctlLogin_OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        e.Authenticated = false;
        if (Page.IsValid)
        {
            e.Authenticated = true;
        }
    }

    protected void ctlLogin_OnLoggedIn(object sender, EventArgs e)
    {

        if (LCAAuthentication.IsRole(UserGroup.LCA_Administrator))
        {
            // If LCA_Admin is logged in, Go to Admin page
            PageHelper.ClientPageRedirect(LCAAuthentication.AdminUrl);
        }
        else
        {
            PageHelper.ClientPageRedirect(LCAAuthentication.HomePageId);
        }

        
    }

}